<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Annex extends CI_Controller {
 function __construct()
 {
   parent::__construct();
   $this->load->model('muser');
   $this->load->library('form_validation');
   $this->load->library('pagination');
 }
 function index(){ 	
 	 if ($this->input->post('Annex_ID')!=NULL)
 	 {
 	 	$this->form_validation->set_rules('Annex_ID','Annex_ID','trim|integer|callback_check_Annex');		
		if ($this->form_validation->run()==FALSE){
			$data['error']='Annex_ID is existed';
		}else{
			$DT['Annex_ID']=$this->input->post('Annex_ID');	
		 	$DT['Contract_ID']=$this->input->post('Contract_ID');
			$DT['Salary']=$this->input->post('Salary');
			$DT['AnnexDate']=$this->input->post('AnnexDate');
			$this->muser->addData('Annex',$DT);			
		} 	
			
 	 }	
 	 $config['base_url'] = base_url().'annex/index'; 
	 $config['total_rows'] = $this->muser->num_rows('Annex');
	 
	 $config['per_page'] = 10; // xác định số record ở mỗi trang  
     $config['uri_segment'] = 3; // xác định segment chứa page number  
	 $this->pagination->initialize($config); 
	 $data['result']=$this->muser->getalldata('Annex',$config['per_page'],$this->uri->segment(3));	
	
	 $data['contract']=$this->getContractID();
	 $this->load->view('_header');
     $this->load->view('annex/annex_view',$data); 
     $this->load->view('_footer');
 }
 function delete($Annex_ID){
	$this->muser->delColumn('Annex','Annex_ID',$Annex_ID);
	redirect('annex/index');
 }
 
 function edit1 ()
 {
 	$DT['Annex_ID']=$this->input->post('Annex_ID');	
	$DT['Contract_ID']=$this->input->post('Contract_ID');
	$DT['Salary']=$this->input->post('Salary');
	$DT['AnnexDate']=$this->input->post('AnnexDate');
	$this->muser->updateData('Annex','Annex_ID',$DT['Annex_ID'],$DT);
	$data['error']='Edit successful!';	 	
	redirect('annex/index',$data);		
 } 
 function edit($str)
 {	
 	$result=$this->muser->getRdata('Annex','Annex_ID',$str);
	$data['result']=$result;
	$data['contract']=$this->getContractID();	
 	$this->load->view('_header');
	$this->load->view('annex/editAnnex_view',$data);	
	$this->load->view('_footer');
 }
 
 function check_Annex($str){
 		return $this->muser->checkData('Annex','Annex_ID',$str);		
 }
 function getContractID(){
 	 $lab1=$this->muser->getData('Contract');
	 foreach ($lab1 as $row) {
		 $lab[$row->Contract_ID]=$row->Contract_ID.'-'.$row->Staff_ID;
	 }
	 return $lab;
 }
}